package com.easy.ui.config;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import com.easy.MslApp;
import com.easy.R;
import com.easy.base.activity.BaseActivity;
import com.easy.base.util.Util;
import com.easy.tool.ToastUtils;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ConfigActivity extends BaseActivity<ConfigModel, ConfigView, ConfigPresent> implements ConfigView{
        private String tag = "ConfigActivity";
        @Bind(R.id.iv_title_left)
        ImageView ivTitleLeft;
        @Bind(R.id.tv_title)
        TextView tvTitle;
        @Bind(R.id.ivu)
        ImageView ivu;
        @Bind(R.id.login_id)
        EditText loginId;
        @Bind(R.id.ivp)
        ImageView ivp;
        @Bind(R.id.login_p)
        EditText loginP;
        @Bind(R.id.tvr)
        TextView tvr;
        @Bind(R.id.loginbt)
        Button loginbt;
        String cid = "";
        String add = "";

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_config);
            ButterKnife.bind(this);
            tvTitle.setText("网络配置");
            loginId.setText(MslApp.sSharedPreferences.getString(Util.cidk, ""));
            loginP.setText(MslApp.sSharedPreferences.getString(Util.addk, ""));
//            loginId.setText(MslApp.sSharedPreferences.getString(Util.cidk, "9999"));
//            loginP.setText(MslApp.sSharedPreferences.getString(Util.addk, "http://english.sswl315.com"));
        }

        @Override
        public ConfigModel createModel() {
            return new ConfigModelImpl();
        }

        @Override
        public ConfigView createView() {
            return this;
        }

        @Override
        public ConfigPresent createPresenter() {
            return new ConfigPresent();
        }

        @Override
        public void config(String str) {
            tvr.setText(str);
        }

        @OnClick({R.id.iv_title_left, R.id.loginbt})
        public void onViewClicked(View view) {
            switch (view.getId()) {
                case R.id.iv_title_left:
                    finish();
                    break;
                case R.id.loginbt:
                    cid = loginId.getText().toString();
                    if (cid.length() == 0) {
                        ToastUtils.showSingleToast(this, "请填写企业编号");
                        return;
                    }
                    add = loginP.getText().toString();
                    if (add.length() == 0) {
                        ToastUtils.showSingleToast(this, "请填写服务器地址");
                        return;
                    }
                    presenter.config(add,cid);
                    break;
            }
        }

}
